//
//  UIView+LongPressAccusation.m
//  Friend_Holiday_iPhone
//
//  Created by Mac020 on 15/4/29.
//  Copyright (c) 2015年 tongcheng. All rights reserved.
//

#import "UIView+LongPressAccusation.h"
//#import "AccusationViewController.h"

@implementation UIView (LongPressAccusation)

//添加长按手势，增加举报
- (void)longPressAccusation:(NSString*)accusationType relativeId:(NSString*)generalId{
    [self setAccusationType:accusationType];
    [self setGeneralId:generalId];
    UILongPressGestureRecognizer *recognizer = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longPress:)];
    recognizer.minimumPressDuration = 1;
    [self addGestureRecognizer:recognizer];
}

- (BOOL)canBecomeFirstResponder{
    return YES;
}

-(void)longPress:(UIGestureRecognizer*)recognizer{
    if (recognizer.state == UIGestureRecognizerStateEnded) {
        
    }else{
        [self becomeFirstResponder];
        UIMenuItem *copyLink = [[UIMenuItem alloc] initWithTitle:@"举报" action:@selector(report:)];
        [[UIMenuController sharedMenuController] setMenuItems:[NSArray arrayWithObjects:copyLink, nil]];
        [[UIMenuController sharedMenuController] setTargetRect:self.frame inView:self.superview];
        [[UIMenuController sharedMenuController] setMenuVisible:YES animated:YES];
    }
}

- (void)report:(id)sender{
    NSLog(@"举报功能");
//    AccusationViewController *accusationVc = [[AccusationViewController alloc] initWithNibName:@"AccusationViewController" bundle:nil];
//    if ([[self getAccusationType] isEqualToString:@"1"]) {
//        accusationVc.imageId = [self getGeneralId];
//        accusationVc.travelId = @"";
//        accusationVc.userId = @"";
//    }else if ([[self getAccusationType] isEqualToString:@"2"]){
//        accusationVc.imageId = @"";
//        accusationVc.travelId = [self getGeneralId];
//        accusationVc.userId = @"";
//    }else if ([[self getAccusationType] isEqualToString:@"3"]){
//        accusationVc.imageId = @"";
//        accusationVc.travelId = @"";
//        accusationVc.userId = [self getGeneralId];
//    }
//    UINavigationController *accNavigation = [[UINavigationController alloc] initWithRootViewController:accusationVc];
//    [[UIApplication sharedApplication].keyWindow.rootViewController presentViewController:accNavigation animated:YES completion:nil];
}

#pragma --mark 动态属性
static char accusationTypeKey;
- (void) setAccusationType:(NSString *)accType{
    objc_setAssociatedObject(self, &accusationTypeKey, accType, OBJC_ASSOCIATION_COPY_NONATOMIC);
}

- (NSString *)getAccusationType{
    return objc_getAssociatedObject(self, &accusationTypeKey);
}

static char generalIdKey;
- (void) setGeneralId:(NSString *)genId{
    objc_setAssociatedObject(self, &generalIdKey, genId, OBJC_ASSOCIATION_COPY_NONATOMIC);
}

- (NSString *)getGeneralId{
    return objc_getAssociatedObject(self, &generalIdKey);
}
@end
